package ua.races.command.implementation;

import org.apache.log4j.Logger;
import ua.races.command.ServletCommand;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LogoutCommand implements ServletCommand {
    private static final Logger log = Logger.getLogger(StaffCheckCommand.class.getName());

    public void execute(HttpServletRequest req, HttpServletResponse resp, ServletContext context) {

        req.getSession(true).removeAttribute(SESS_AUTH);
        req.getSession(true).invalidate();
        
        req.setAttribute("message", "Logged Out!");
        req.setAttribute("URL", "index.jsp");
        try {
            context.getRequestDispatcher("/redirection.jsp").forward(req, resp);
        } catch (ServletException e) {
            log.error(e);
        } catch (IOException e) {
            log.error(e);
        }

    }
}
